#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
int main()
{
    long long n, i, j, k = 0, t = 0, sum = 0, x;
    cin >> n;
    static int a[200001], b[200001];
    for (i = 0; i < n; i++)
    {
        cin >> x;
        a[x] = i;
    }
    for (i = 0; i < n; i++)
        cin >> b[i];
    for (i = 0; i < n; i++)
        while (b[a[i]] != i)
        {
            t = b[a[a[i]]];
            b[a[a[i]]] = a[i];
            a[i] = t;
        }
    cout << sum << endl;
    return 0;
}